package com.kaifamiao.game;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class WerewolfDealer implements Dealer {
    private final List<String> list = WereWolf.getCards();
    private final int PEOPLE_NUMBER = 12;

    @Override
    public List<String> deal() {
        return deal(3);
    }
@Test
    public List<String> deal(int count) {
        List<String> cardInHand = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            shuffle();
        }
        for (Integer n : random()) {
            cardInHand.add(list.get(n));
        }
        return cardInHand;
    }

    private List<Integer> random() {
        List<Integer> rand = new ArrayList<>();
        for (int i = 0; i < PEOPLE_NUMBER; i++) {
            int num = (int)(Math.random()*PEOPLE_NUMBER);
            if (!rand.contains(num)) {
                rand.add(num);
            } else {
                i--;
            }
        }
        return rand;
    }

    @Override
    public void shuffle() {
        Collections.shuffle(list);
    }
}
